package com.example.riceexambackend.dao.mapper;

import com.example.riceexambackend.dao.dataobject.ExamDO;
import com.example.riceexambackend.dao.dataobject.QuestionTypeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExamMapper {

    /**
     * 插入试卷记录
     * @param examDO
     */
    @Insert("insert into t_exam (exam_name, exam_start_time, exam_end_time, exam_duration, exam_user_id) values (#{examName}, #{examStartTime}, #{examEndTime}, #{examDuration}, #{examUserId})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertExam(ExamDO examDO);

    /**
     * 根据id查询考试
     * @param examId
     */
    @Select("select * from t_exam where id = #{examId} and delete_flag = 0")
    ExamDO selectById(@Param("examId") Long examId);

    /**
     * 根据id修改考试总分和总题数
     * @param
     */
    @Select("update t_exam set exam_total_score = #{examTotalScore},exam_total_count = #{examTotalCount} where id = #{id} and delete_flag = 0")
    void updateTotalScoreAndTotalCountById(ExamDO examDO);

    /**
     * 根据名称查询题型
     * @param questionTypeName
     */
    @Select("select * from t_question_type where question_name = #{questionTypeName}")
    QuestionTypeDO selectByName(@Param("questionTypeName") String questionTypeName);

    /**
     * 查询所有试卷
     */
    @Select("select * from t_exam where delete_flag = 0")
    List<ExamDO> selectList();

    /**
     * 根据id更新题型记录
     * @param questionTypeDO
     */
    @Update("update t_question_type set question_name = #{questionName},question_score = #{questionScore} where id = #{id}")
    void updateById(QuestionTypeDO questionTypeDO);

    /**
     * 根据id删除试卷记录
     * @param examId
     */
    @Delete("update t_exam set delete_flag = 1 where id = #{examId}")
    void deleteById(@Param("examId") Long examId);
}
